function get_q(){
	return '{"query":[{' +
				'"amount_raised":null,' +
				'"company_invested":{' +
					'"name":null,'+
					'"id":null,'+				
					'"area_of_expertise":[{"name":null,"id":null}],' +
					'"develops_treatments_for_disease":[{"name":null,"id":null}],' +
					'"/business/company/headquarters":[{"optional":true,'+
						'"*":[],'+
						'"citytown" : {"optional":true,"id" : null,"guid":null, "name" : null},'+
						'"state_province_region":{"optional":true,"id" : null,"guid":null, "name" : null},'+
						'"street_address":[],'+//[{"id" : null,"name" : null}],'+
						'"postal_code":{"optional":true,"id" : null, "guid":null, "name" : null}'+
					'}]'+								
				'},' +
				'"date":null,' +
				'"sort":"-date",' +
				'"investment_round":null,' +
				'"investors":[],' +
				'"web_reference":[],' +
				'"limit":10000,'+
				'"type":"/base/bioventurist/bv_investment_round"'+
				'}]' +
 				'}';
}

function get_q_investors(){
	return '{"query":[{'+
  					'"type": "/base/bioventurist/bv_venture_investor",'+
  					'"name":null,'+
  					'"limit":10000,'+
  					'"name":null,'+
  					'"id":null,'+
  					'"a:investment_round":[{"return":"count"}],'+
  					'"investment_round": [{'+
    					'"investment_round": null,'+
    					'"amount_raised": null,'+
    					'"date": null,'+
    					//'"sort":"investment_round",'+
    					'"sort":"-date",'+
    					'"company_invested": {'+
      						'"name": null,'+
      						'"id":   null'+
    					'}'+
  					'}]'+
  					
				'}]'+
			'}';
}

function create_investor_table(url, html_id, biov_domain, q){
	
	perform_freebase_read(
	url,
	q,
	function (msg) {
		
		var investors = null;
		investors = msg.result[0];
        if (!investors) return;
		
		// Obtain all of the companies from the list:
		var investorList = msg.result;
	
		var investorTable = new google.visualization.DataTable();
		investorTable.addColumn('string', 'Investor');
		investorTable.addColumn('number', '#');
		investorTable.addColumn('string', 'Investments');
 		investorTable.addRows(investorList.length);
		
		for(var i=0;i<investorList.length; i++){
			var investor = investorList[i];
			var investor_name = '<a href="/vcfirm' + investor.id + '">' + investor.name  + '</a>'//investor.name;
			var num_investments = investor["a:investment_round"][0];
			var investment_rounds = investor.investment_round;
			var s = '<table>';
			for(var j=0;j<investment_rounds.length; j++){
				s += '<tr>'
				var investment_round = investment_rounds[j];
				var company = investment_round.company_invested;
				var amount = (investment_round.amount_raised / 1000000) +'M';
				s += ('<td>'+investment_round.investment_round + '</td>');
				s += ('<td>'+ amount +'</td>');
				s += ('<td>'+investment_round.date  + '</td>');
				s += ('<td>'+'<a href="/company' + company.id + '">' + company.name  + '</a></td>');
				s += '</tr>'
			}
			s += '</table>'
	 		investorTable.setCell(parseFloat(i), 0, investor_name);			
	 		investorTable.setCell(parseFloat(i), 1, num_investments);			
	 		investorTable.setCell(parseFloat(i), 2, s);			

		}
		var table = new google.visualization.Table(document.getElementById(html_id));
   	    
   	    table.draw(investorTable, {allowHtml:true, sortColumn:1, sortAscending:false});		    
		
	},
	function(m){}
);
}
function create_vc_financing_table(url, html_id, biov_domain, q){
	
	perform_freebase_read(
	url,
	q,
	function (msg) {
		
		var investment = null;
		investment = msg.result[0];
        if (!investment) return;
		
		// Obtain all of the companies from the list:
		var investmentList = msg.result;
	
		var finance = new google.visualization.DataTable();
		finance.addColumn('string', 'Company');
		finance.addColumn('string', 'Round');
		finance.addColumn('number', 'Amount ($US M)');
		finance.addColumn('string', 'Date');
		finance.addColumn('string', 'Area of Expertise');
		finance.addColumn('string', 'Medical Conditions of Interest');
		//finance.addColumn('string', 'More Info');
 		finance.addRows(investmentList.length);
	
					
		for (var i in investmentList) {
		    var c = investmentList[i].company_invested.name;
		    var c_id = investmentList[i].company_invested.id;
		    var company = '<a href="/company' + c_id + '">' + c + '</a>'
		    var amount = investmentList[i].amount_raised / 1000000;
		    var date = investmentList[i].date;
		    var round = investmentList[i].investment_round;
		    
		    var investors = investmentList[i].investors;
		    var investorList = '';
		    for (var j in investors) {
		    	var investor = investors[j];
		    	investorList += '<a href="/vcfirm/' + investor + '">' + investor + '</a>';
				investorList += ( j < investors.length-1 ? ', ' :"");
		    }
			
			// Make a list of the technologies
		    var technologies = investmentList[i].company_invested.area_of_expertise;
		    //var technologies = investmentList[i]["/base/bioventurist/science_or_technology_company/area_of_expertise"];
		    var technologies_list = '';
		    for (var j=0;j<technologies.length; j++) {
		    	var technology = technologies[j];
		    	technologies_list += '<a href="/technology' + technology.id + '">' + technology.name + '</a>';
				technologies_list += ( j < technologies.length-1 ? ', ' :"");
		    }

			// Make a list of the medical conditions
		    var med_conditions = investmentList[i].company_invested.develops_treatments_for_disease;
		    var med_conditions_list = '';
		    for (var j=0;j<med_conditions.length; j++) {
		    	var med_condition = med_conditions[j];
		    	med_conditions_list += '<a href="/disease' + med_condition.id + '">' + med_condition.name + '</a>';
				med_conditions_list += ( j < med_conditions.length-1 ? ', ' :"");
		    }
			
			var web_refs = investmentList[i].web_reference;
		    var refList = '';
		    for (var j in web_refs) {
		    	var ref = web_refs[j];
		    	refList += '<a href="'+ref+'">' + 'ref' + '</a>';
				refList += ( j < web_refs.length-1 ? ', ' :"");
		    }
	 		finance.setCell(parseFloat(i), 0, company);
	 		finance.setCell(parseFloat(i), 1, round);
	 		finance.setCell(parseFloat(i), 2, amount, amount.toString() );
	 		finance.setCell(parseFloat(i), 3, date);
	 		//finance.setCell(parseFloat(i), 4, investorList);
	 		finance.setCell(parseFloat(i), 4, technologies_list);
	 		finance.setCell(parseFloat(i), 5, med_conditions_list);
	 		//finance.setCell(parseFloat(i), 5, refList);
	
		}
		
		var table = new google.visualization.Table(document.getElementById(html_id));
   	    table.draw(finance, {allowHtml:true, sortColumn:3, sortAscending:false});		    
	},
	function(m){}
);
}